<template>
  <div class="infoBox appCon page_pos_style" :style="{ top: `${phoneStatusBarHeight}`}" style="padding:unset;">
    <!-- 顶部盒子 -->
    <!-- <van-nav-bar title="设置" fixed placeholder :border="false"> -->
      <!-- 顶部返回按钮 -->
      <!-- <template #left>
        <van-icon name="arrow-left" size="18" @click="$router.go(-1)" />
      </template>
    </van-nav-bar> -->
    <navbar :title="title"></navbar>

 <div class="font_style_box">
    <!-- this is SetInfopage -->
 <van-cell icon="medal-o" title="车煮用户协议" :to="{name:'userAgreement'}" is-link   />
 <van-cell icon="shop-collect-o" title="车煮隐私政策" :to="{name:'privacyAgree'}" is-link   />
 <van-cell icon="shop-o" title="关于车煮平台" :to="{name:'aboutCookCar'}" is-link   />

  <van-cell icon="phone" title="客服热线"  is-link  value="4009991024" >
    <a :href="'tel:'+4009991024">4009991024</a>
  </van-cell>
 <!-- <div class="marTop t-center">
	 <van-button class="coll_80" type="primary" size="small" square>退出登录</van-button>
 </div> -->
 
  <div class="but">
    <van-button id="testdiv" block style="color:#ffffff !important;" type="primary">退出登录</van-button>
  </div>
  <div class="but">
    <van-button block style="color:#ffffff !important;" type="primary" @click="cancelAccount">注销账号</van-button>
  </div>
 </div>
</div>

</template>
<script>
import { Toast,Dialog  } from 'vant';
import {getLogoutC} from './api'
export default {
  name: "SetInfo",
  data() {
    return {
        // header栏 => 标题
        title:"设置",
        // 获取屏幕状态栏高度
        phoneStatusBarHeight:''
    }
  },
  methods: {
    // 获取路由链接上拼接的token值
    getTokenInUrl() {
      var url = window.location.href;
      if (url.indexOf("token") > 0) {
        let getTokenParams = window.location.href.split("token=")[1];
        getTokenParams=getTokenParams.split("&")[0];
        if (getTokenParams.length >= 32) {
          getTokenParams = getTokenParams.substr(0, 32);
          console.log('%c [ getTokenParams ]', 'font-size:13px; background:pink; color:#bf2c9f;', getTokenParams)
          sessionStorage.setItem("token", getTokenParams);
        }
      }
    },
    // 注销账号
    cancelAccount(){
      Dialog.confirm({
        title: '提示',
        message: '确认后会删除个人信息，请谨慎操作',
      })
        .then(async () => {
          const data = await getLogoutC()
          if(data.code !== 0) return Toast(data.msg)
          // h5与uniapp的交互 => 点击返回上一页
          if (window.UniAppJSBridge) {
            uni.postMessage({
              data:{
                type:0,
              }
            })
          }
        })
        .catch(() => {
        });
    }
  },
    /* watch: {
      phoneStatusBarHeight(val, oldVal) {
        Toast("phoneStatusBarHeight = " + val + " , oldValue = " + oldVal)
      }
    }, */
  created() {
      // 获取屏幕状态栏高度
      if (window.phoneStatusBarHeight !== null || window.phoneStatusBarHeight !== '' || window.phoneStatusBarHeight !== undefined) {
        this.phoneStatusBarHeight = window.phoneStatusBarHeight
      }
      let localHeight = localStorage.getItem('phoneStatusBarHeight')
      if (localHeight !== null || localHeight !== '' || localHeight !== undefined) {
        this.phoneStatusBarHeight = localHeight
      }
    // 修改页面标题
    document.title = "设置"
    // 获取路由链接上拼接的token值
    this.getTokenInUrl()
  },
  mounted() {
    // h5与uniapp的交互 => 点击退出登录
    document.addEventListener('UniAppJSBridgeReady',function(){
      document.getElementById('testdiv').addEventListener('click',function(){
        uni.postMessage({
          data:{
            type:0, // 0 => 退出  ||  1 => 分享
          }
        })
      })
    })
  },
};
</script>
<style lang="less">
.page_pos_style{
  .font_style_box{
    .van-cell{
      .van-cell__title {
        font-size: 16px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        // height: 100px;
        width: 100%;
      }
      .van-cell__value {
        font-size: 16px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        // height: 100px;
        width: 100%;
      }
      .van-icon{
        font-size: 18px;
      }
    }
  }
  .but{
    margin: 20px 12px;
    .van-button{
      color: black !important;
      font-size: 17px;
      font-family: PingFang SC;
      font-weight: 500;
      color: #333333;
    }
  }
}
</style>
